#include <bits/stdc++.h>

using namespace std;

class Solution
{
    long long single(int l, int r)
    {
        // 直接模拟 log4(r-l)
        long long sum_steps = 0;
        long long a = 1; 
        int s = 1;       

        while (a <= r)
        {
            long long b = 4 * a - 1; 
            long long left = max((long long)l, a);
            long long right = min((long long)r, b);
            if (left <= right)
            {
                long long count = right - left + 1;
                sum_steps += count * s;
            }
            a *= 4;
            s += 1;
        }
        return (sum_steps + 1) / 2;
    }

public:
    long long minOperations(vector<vector<int>> &queries)
    {
        long long total = 0;
        for (const auto &query : queries)
        {
            int l = query[0], r = query[1];
            total += single(l, r);
        }
        return total;
    }
};